<?php defined("MAIN_DIR") or die("No direct access");

require_once ADMIN.HEADFILE;
?>
<div align="left">
<h1>РКО</h1><?php
$banks_query = 
"select `B`.`name`,`R`.`rko_id`,`R`.`regionally`,`C`.`path`,`C`.`city_name`
from `bank` as `B`
left join `city` as `C`
	on `B`.`city_id` = `C`.`city_id`
,`rko` as `R`
where
	`B`.`bank_id` = `R`.`bank_id`
order by `B`.`name`";

$limit = 10;
$banks_result = mysql_query($banks_query);
$count = mysql_num_rows($banks_result);
$page = 1;
if (isset($_GET['page']))
	$page = $_GET['page'];
$max_page = ceil($count/$limit);
if ($max_page == 0)
	$max_page++;
if ($page > $max_page)
	$page = $max_page;
elseif ($page < 1)
	$page = 1;
$start_list = (ceil($page)-1)*$limit;
$banks_query .= " limit $start_list,$limit";
$banks_result = mysql_query($banks_query);
$banks_count = mysql_num_rows($banks_result);

?>
<table cellpadding="5" cellspacing="0" class='light'>
	<tr id='header'>
		<td width="30px" style="border-bottom:1px gray solid">ID</td>
		<td width="300px" style="border-bottom:1px gray solid">Банк</td>
		<td width="200px" style="border-bottom:1px gray solid">Действия</td>
	</tr><?php
	while ($bank_row = mysql_fetch_array($banks_result))
	{
		?><tr>
			<td><?php echo $bank_row['rko_id']?></td>
			<td><?php
				if (!$bank_row['regionally']) {
					echo "<a href='/$bank_row[path]/banks/rko/'>$bank_row[name] ($bank_row[city_name])</a>";
				} else {
					echo $bank_row['name']." (Межрегионально)";
				}
			?></td>
			<td>
				<a href='/admin/rko/edit/<?php echo $bank_row['rko_id']?>'>Редактировать</a> |
				<a onclick='return confirm_del()' href='/admin/rko/delete/<?php echo $bank_row['rko_id']?>'>Удалить</a>
			</td>
		</tr><?php
	}
?></table>
<br /><a href='/admin/rko/add/'>Добавить</a>
<br /><?php require_once APP."pageskin.php"; ?>
</div>

<?php require_once ADMIN.FOOTERFILE; ?>